<template>
    <div class="login">
        <h2>土豆集系统</h2>
        <form class="layui-form" method="post" target="_blank" action="">
            <div class="layui-form-item">
                <input type="username" name="loginname" placeholder="用户名" required lay-verify="required"  class="layui-input">
                <i class="layui-icon input-icon">&#xe66f;</i>
            </div>
            <div class="layui-form-item">
                <input type="password" name="password" placeholder="密码" required lay-verify="required"  class="layui-input">
                <i class="layui-icon input-icon">&#xe673;</i>
            </div>
            <div class="layui-form-item">
                <input type="checkbox" name="" lay-skin="primary" title="记住密码" checked=""> <a class="back" href="javascript:;"  style="margin-top: 10px">忘记密码</a>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" lay-submit lay-filter="submit">立即登录</button>

                <!--          <button style="width: 100%" class="layui-btn" id="sub">立即登录</button>-->
            </div>
        </form>
    </div>
</template>

<script>
    export default {
        name: 'Login',
        data () {
            return {
                msg: 'Welcome to Your Vue.js App'
            }
        },
        created() {
            //刷新
            if(location.href.indexOf("#reloaded")==-1){
                location.href=location.href+"#reloaded";
                location.reload();
            }

            let that = this;
            layui.use(['form'], function () {
                var form = layui.form,
                    layer = layui.layer;
                form.render();
                form.on('submit(submit)', function (data) {

                    let loader = layer.load();
                    $.ajax({
                        url : "/sales/Admin!signin2.action",
                        type: "post",
                        async: true,
                        dataType: 'json',
                        data: data.field,
                        success : function(data) {
                            if (data.flag == 1) {
                                that.resetSetItem('userid', data.uid);
                                that.resetSetItem('user', data.uname);
                                //that.resetSetItem('salespermissionsData',JSON.stringify( data));
                                that.resetSetItem('permissions', JSON.stringify(data.permissions));
                                that.$router.push({name: 'Entry'});
                            } else if (data.flag == 0) {
                                that.toast(data.msg);
                            } else {
                                that.toast('系统错误');
                            }
                        },
                        complete: function () {
                            layer.close(loader);
                        },
                        error: function (err) {
                            console.log('err:', err)
                        }
                    });
                    return false;
                });
            });
        },
        methods: {

        }
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
    @import "../../static/admin/css/login.css";
</style>
